package org.nokatag.code;

import java.awt.Font;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Random;

public class RandomFontFactory
implements FontFactory
{

protected java.util.List families;
protected int minSize;
protected int maxSize;
protected boolean randomStyle;

public RandomFontFactory()
{
    families = new ArrayList();
    families.add("Dialog");
    families.add("Monospaced");
    minSize = 45;
    maxSize = 45;
}

public RandomFontFactory(java.util.List families)
{
    this();
    this.families = families;
}

public RandomFontFactory(String families[])
{
    this();
    this.families = Arrays.asList(families);
}

public RandomFontFactory(int size, java.util.List families)
{
    this(families);
    minSize = maxSize = size;
}

public RandomFontFactory(int size, String families[])
{
    this(families);
    minSize = maxSize = size;
}

public void setFamilies(java.util.List families)
{
    this.families = families;
}

public void setMinSize(int minSize)
{
    this.minSize = minSize;
}

public void setMaxSize(int maxSize)
{
    this.maxSize = maxSize;
}

public void setRandomStyle(boolean randomStyle)
{
    this.randomStyle = randomStyle;
}

public Font getFont(int index)
{
    Random r = new Random();
    String family = (String)families.get(r.nextInt(families.size()));
    boolean bold = r.nextBoolean() && randomStyle;
    int size = minSize;
    if(maxSize - minSize > 0)
    {
        size += r.nextInt(maxSize - minSize);
    }
    return new Font(family, bold ? 1 : 0, size);
}
}

